/**
 * 
 * 
 * @author 吕婧
 *
 */
package com.ccb.lms.dao;

import java.sql.SQLException;
import java.util.List;

import com.ccb.lms.model.Library;
import com.ccb.lms.util.BasePage;
import com.ibatis.sqlmap.client.SqlMapClient;

@SuppressWarnings("unchecked")
public class LibraryDAO implements ILibraryDAO {

	private SqlMapClient sqlMapClient = null;

	public boolean deleteLibrary(Integer libraryNO) throws SQLException {
		sqlMapClient.delete("library.deleteLibrary", libraryNO);
		return true;

	}

	public List<Library> getAllLibrary() throws SQLException {
		List<Library> list = null;
		list = sqlMapClient.queryForList("library.getAllLibrary");
		return list;
	}

	public Library getLibraryById(Integer libraryNO) throws SQLException {
		Library library = null;
		library = (Library) sqlMapClient.queryForObject("library.getLibraryById", libraryNO);
		return library;

	}
	

	public List<Library> getLibraryByPage(BasePage basePage) throws SQLException {
		List<Library> list = null;
		list=sqlMapClient.queryForList("library.getLibraryByPage", basePage);
		return list;
	}

	
	public int getLibraryCount() throws SQLException {
		
		return (Integer)sqlMapClient.queryForObject("library.recordCount");
	}

	public boolean insertLibrary(Library library) throws SQLException {
		sqlMapClient.insert("library.insertLibrary", library);
		return true;

	}


	public boolean updateLibrary(Library library) throws SQLException {
		sqlMapClient.update("library.updateLibrary", library);
		return true;

	}

	public BasePage getBasePage(int currentPage, int showRecordNum) throws SQLException {
		return new BasePage(currentPage,getLibraryCount(),showRecordNum);
	}

	public SqlMapClient getSqlMapClient() throws SQLException {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

}
